/**
 * 
 */
package com.Data;


import android.app.AlertDialog;
import android.content.Context;
import android.os.AsyncTask;
import com.SoapClasses.SoapOptions;
import com.shareup.R;
import com.utils.AlertDialogHelper;


/**
 * @author Chris
 * 
 */
public class Options extends AsyncTask<Integer, String, Options> {

    public static final int ACTION_GET = 600;

    public static final int ACTION_SAVE = 650;

    private int AllowFollow;

    private int AllowShare;

    private int BlurCover;

    private onPreferencesGetCompleted callbackGet;

    private onPreferencesUpdateCompleted callbackUpdate;

    private Context context;

    private String Extras;

    private int IdUser;

    private String message;

    private int mode;

    private AlertDialog progress;

    public interface onPreferencesGetCompleted {

        void Completed(Options result);
    }

    public interface onPreferencesUpdateCompleted {

        void Completed(String result);
    }

    public Options() {

        super();
    }

    public Options(Context context) {

        super();
        this.context = context;
    }

    public int getAllowFollow() {

        return this.AllowFollow;
    }

    public int getAllowShare() {

        return this.AllowShare;
    }

    public int getBlurCover() {

        return this.BlurCover;
    }

    public String getExtras() {

        return Extras;
    }

    public int getIdUser() {

        return this.IdUser;
    }

    public void setAllowFollow(int allowFollow) {

        this.AllowFollow = allowFollow;
    }

    public void setAllowShare(int allowShare) {

        this.AllowShare = allowShare;
    }

    public void setBlurCover(int blurCover) {

        this.BlurCover = blurCover;
    }

    public void setCallbackGet(onPreferencesGetCompleted callbackGet) {

        this.callbackGet = callbackGet;
    }

    public void setCallbackUpdate(onPreferencesUpdateCompleted callbackUpdate) {

        this.callbackUpdate = callbackUpdate;
    }

    public void setContext(Context context) {

        this.context = context;
    }

    public void setExtras(String extras) {

        this.Extras = extras;
    }

    public void setIdUser(int idUser) {

        this.IdUser = idUser;
    }

    /* 
     * 
     */
    @Override
    protected Options doInBackground(Integer... params) {

        mode = params[0];

        SoapOptions sop = new SoapOptions();
        switch (mode) {
            case ACTION_SAVE:
                String[] data = new String[4];
                data[0] = String.valueOf(this.IdUser);
                data[1] = String.valueOf(this.AllowFollow);
                data[2] = String.valueOf(this.AllowShare);
                data[3] = String.valueOf(this.BlurCover);

                String res = sop.updateOptions(data);
                Options opt = new Options();
                opt.setExtras(res);

                return opt;
            case ACTION_GET:

                return sop.getOptions(this.IdUser);
            default:
                return null;
        }
    }

    @Override
    protected void onPostExecute(Options result) {

        progress.dismiss();
        if (callbackGet != null)
            callbackGet.Completed(result);

        if (callbackUpdate != null)
            callbackUpdate.Completed(result.getExtras());

    }

    @Override
    protected void onPreExecute() {

        message = context.getString(R.string.dialog_wait);
        progress = AlertDialogHelper.setProgressDialog(progress, message, context);
        progress.show();
    }
}
